<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :destroyOnClose="true"
    @cancel="handleCancel"
    :footer="null"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-collapse v-model="activeKey">

          <a-collapse-panel header="基本配置" key="1">
            <a-row>
              <a-col :span="4">
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="readDate" type="primary" icon="search" >读取日期</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 23 }">
                  <a-date-picker placeholder="请选择日期时间"
                                 v-decorator="[ 'dateTime',validatorRules.dateTime]" :trigger-change="true"
                                 format="YYYY-MM-DD HH:mm:ss" />
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="setDate" type="primary" icon="plus">写入日期</a-button>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="4" >
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="readLightGateWay" type="primary" icon="search">读分控地址</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 23 }">
                  <a-input maxlength ="15"  v-decorator="[ 'lightGateWay', validatorRules.lightGateWay]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="setLightGateWay" type="primary" icon="plus">写分控地址</a-button>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="4">
                <a-form-item :label-col="{ span: 9 }" :wrapper-col="{ span: 15 }">
                  <a-button @click="getOpenStatus" type="primary" icon="search">读开关状态</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item  :wrapper-col="{ span: 22 }">
                  <a-input   v-decorator="[ 'openstatusvalue', validatorRules.openstatusvalue]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-button @click="setOpenStatus" type="primary" icon="plus">写入开关状态</a-button>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="模式配置" key="9">
            <a-row style="text-align: center">
              <a-col :span="12">
                <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-button  @click="getTimeFrameAndDimming" type="primary" icon="search">读取时段</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-button @click="setTimeFrameAndDimming" type="primary" icon="plus" >写入时段</a-button>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="5">
                <a-form-item label=" 时段" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                  <a-time-picker placeholder="选择时间" v-decorator="[ 'commandTimea',validatorRules.commandTimea]" :trigger-change="true"  format="HH:mm" style="width: 100%" />
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 16 }">
                  范围:00:00-03:00
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item label="亮度" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-input   v-decorator="[ 'brightValuea', validatorRules.brightValuea]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="5">
                <a-form-item label="日出" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                  <a-input   v-decorator="[ 'v1Time', validatorRules.v1Time]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item  :wrapper-col="{ span: 20 }">
                  <j-dict-select-tag style="width: 100%" v-decorator="['typeb', validatorRules.typeb]" :triggerChange="true" placeholder="请选择"
                                     dictCode="glr_pattern_time"/>
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-input placeholder="选择时间"  v-decorator="[ 'commandTimeb']"  style="width: 100%" />
                </a-form-item>
              </a-col>
              <a-col :span="2">
                <a-form-item label="" :wrapper-col="{ span: 10 }">
                  分钟
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item label="亮度" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-input   v-decorator="[ 'brightValueb', validatorRules.brightValueb]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>



            <a-row>
              <a-col :span="5">
                <a-form-item label="日落" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                  <a-input   v-decorator="[ 'v2Time', validatorRules.v2Time]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item  :wrapper-col="{ span: 20 }">
                  <j-dict-select-tag style="width: 100%" v-decorator="['typec', validatorRules.typec]" :triggerChange="true" placeholder="请选择"
                                     dictCode="glr_pattern_time"/>
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-input placeholder="选择时间"  v-decorator="[ 'commandTimec']"  style="width: 100%" />
                </a-form-item>
              </a-col>
              <a-col :span="2">
                <a-form-item label="" :wrapper-col="{ span: 10 }">
                  分钟
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item label="亮度" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-input   v-decorator="[ 'brightValuec', validatorRules.brightValuec]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>


            <a-row>
              <a-col :span="5">
                <a-form-item label="时段4" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                  <a-time-picker placeholder="选择时间"  v-decorator="[ 'commandTimed']" :trigger-change="true"  format="HH:mm" style="width: 100%" />
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 16 }">
                  范围:20:00-21:59
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item label="亮度" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-input   v-decorator="[ 'brightValued', validatorRules.brightValued]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>


            <a-row>
              <a-col :span="5">
                <a-form-item label="时段5" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                  <a-time-picker placeholder="选择时间"  v-decorator="[ 'commandTimee']" :trigger-change="true"  format="HH:mm" style="width: 100%" />
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 16 }">
                  范围:22:00-23:59
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item label="亮度" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-input   v-decorator="[ 'brightValuee', validatorRules.brightValuee]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item label="日出时间" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
                  <a-input v-bind:readonly="true"  v-decorator="[ 'v3Time', validatorRules.v3Time]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item label="日落时间" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
                  <a-input  v-bind:readonly="true" v-decorator="[ 'v4Time']" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置系统IP" key="2" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setIP" type="primary" icon="plus">设置系统IP</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getIP" type="primary" icon="search">读取系统IP</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  label="网络" :label-col="{ span: 5 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['netvalue', validatorRules.netvalue]" :triggerChange="true" placeholder="网络类型"
                                      dictCode="glr_gate_way_network"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item  label="通道" :label-col="{ span: 5 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['channelvalue', validatorRules.channelvalue]" :triggerChange="true" placeholder="通道"
                                      dictCode="glr_channel"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item label="IP"  :label-col="{ span: 5}" :wrapper-col="{ span: 15 }">
                  <a-input   v-decorator="[ 'ipvalue', validatorRules.ipvalue]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="8" >
                <a-form-item label="端口" :label-col="{ span: 5}" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'portvalue', validatorRules.portvalue]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置系统周期" key="3" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setGateWayMsg" type="primary" icon="plus">设置系统周期</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getGateWayMsg" type="primary" icon="search">读取系统周期</a-button>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="6">
                <a-form-item  label="心跳周期" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'heartbeat', validatorRules.heartbeat]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item label="数据周期" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'dataCycle', validatorRules.dataCycle]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6" >
                <a-form-item label="测量周期" v-show="false" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'testCycle', validatorRules.testCycle]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6" >
                <a-form-item label="轮询周期" v-show="false" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'pollingCycle', validatorRules.pollingCycle]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="测试" key="4" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setPacketLoss" type="primary" icon="plus">开始测试</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getPacketLoss" type="primary" icon="search">获取测试结果</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="6">
                <a-form-item  label="分控序号" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'lightCode', validatorRules.lightCode]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item label="测试次数" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'testCount', validatorRules.testCount]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6" >
                <a-form-item label="测试结果" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'testResult', validatorRules.testResult]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6" >
                <a-form-item label="测试间隔" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'testTime', validatorRules.testTime]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置GPS" key="5" >
            <a-row style="text-align: center">
              <a-col :span="24">
                <a-form-item>
                  <a-button @click="getGPS" type="primary" icon="search">读取GPS</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="6" >
                <a-form-item label="经度" :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'longitude', validatorRules.longitude]" placeholder="请输入经度"></a-input>
                </a-form-item>
              </a-col>


              <a-col :span="6" >
                <a-form-item label="纬度" :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'latitude', validatorRules.latitude]" placeholder="请输入纬度"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="6" >
                <a-form-item label="海拔" :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'altitude', validatorRules.altitude]" placeholder="请输入海拔"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="6" >
                <a-form-item label="搜星数" :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'gpsCam', validatorRules.gpsCam]" placeholder="请输入搜星数"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="6" >
                <a-form-item label="时段经度" :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'timeLongitude', validatorRules.timeLongitude]" placeholder="请输入时段经度"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="6" >
                <a-form-item label="时段纬度" :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'timeLatitude', validatorRules.timeLatitude]" placeholder="请输入时段纬度"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置光照" key="10" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setIlluminance" type="primary" icon="plus">设置光照</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getIlluminance" type="primary" icon="search">读取光照</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  label="光照开关" :label-col="{ span: 8}" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['onOff', validatorRules.onOff]" :triggerChange="true" placeholder="请选择"
                                      dictCode="glr_on_off"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item label="光照度"  :label-col="{ span: 5}" :wrapper-col="{ span: 15 }">
                  <a-input   v-decorator="[ 'illuminance', validatorRules.illuminance]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="8" >
                <a-form-item label="结果" :label-col="{ span: 5}" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'illuminanceValue', validatorRules.portvalue]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置厂家设定" key="21" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setManufacturerSet" type="primary" icon="plus">设置厂家设定</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getManufacturerSet" type="primary" icon="search">读取厂家设定</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  label="心跳开关" :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['heartbeatSwitch', validatorRules.heartbeatSwitch]" :triggerChange="true" placeholder="请选择心跳开关"
                                      dictCode="glr_off_on"/>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  label="上传开关" :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['uploadSwitch', validatorRules.uploadSwitch]" :triggerChange="true" placeholder="请选择上传开关"
                                      dictCode="glr_off_on"/>
                </a-form-item>
              </a-col>

            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置额定功率" key="22" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setRatedPower" type="primary" icon="plus">设置额定功率</a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getRatedPower" type="primary" icon="search">读取额定功率</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  label="灯1功率" :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <a-select v-decorator="[ 'lightOneTypeCode', validatorRules.lightOneTypeCode]" placeholder="请选择灯1功率">
                    <a-select-option v-for="item in lightTypeList" :key="item.id" :value="item.power">
                      {{item.name}}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  label="灯2功率" :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <a-select v-decorator="[ 'lightTwoTypeCode', validatorRules.lightTwoTypeCode]" placeholder="请选择灯2功率">
                    <a-select-option v-for="item in lightTypeList" :key="item.id" :value="item.power">
                      {{item.name}}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  label="灯数量" :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['lightNumber', validatorRules.lightNumber]" :triggerChange="true" placeholder="请选择灯数量"
                                      dictCode="glr_light_number"/>
                </a-form-item>
              </a-col>

            </a-row>
          </a-collapse-panel>

          <a-collapse-panel header="设置系统重启" key="23" >

            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setSystemRestart" type="primary" icon="plus">设置系统重启</a-button>
                </a-form-item>
              </a-col>
            </a-row>

          </a-collapse-panel>

          <a-collapse-panel header="设置版本号" key="24" >
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getVersionNo" type="primary" icon="search">读取版本号</a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  label="硬件版本" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'hardwareVersion', validatorRules.hardwareVersion]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  label="软件版本" :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'softwareVersion', validatorRules.softwareVersion]" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>

            </a-row>
          </a-collapse-panel>

        </a-collapse>
      </a-form>
    </a-spin>

  </a-modal>
</template>

<script>

    import { httpAction } from '@/api/manage'
    import pick from 'lodash.pick'
    import { validateDuplicateValue } from '@/utils/util'
    import JDate from '@/components/jeecg/JDate'
    import moment from 'moment';
    export default {
        name: "GlrLightSetParameter",
        components: {
            JDate
        },
        data () {
            return {
                form: this.$form.createForm(this),
                title:"操作",
                width:1000,
                activeKey: ['1'],
                visible: false,
                gateWayCode:'',
                lightTypeList:[],
                disableMixinCreated:true,
                model: {},
                labelCol: {
                    xs: { span: 24 },
                    sm: { span: 5 },
                },
                wrapperCol: {
                    xs: { span: 24 },
                    sm: { span: 16 },
                },
                confirmLoading: false,
                validatorRules: {
                    phoneNumber: {rules: [
                        ]},
                    phoneType: {rules: [
                        ]},
                    gatewayModel: {rules: [
                            {required: true, message: '请输入网关型号!'},
                        ]},
                    gatewayType: {rules: [
                            {required: true, message: '请输入网关类型!'},
                        ]},
                    longitude: {rules: [
                        ]},
                    latitude: {rules: [
                        ]},
                    gatewayName: {rules: [
                            {required: true, message: '请输入网关名称!'},
                        ]},
                    gateWayCode: {rules: [
                            {required: true, message: '请输入网关编号!'},
                        ]},
                    lightGateWay: {rules: [
                            {required: true, message: '请输入分控地址!'},
                        ]},
                    openstatusvalue: {rules: [
                            {required: true, message: '请输入开关值!'},
                        ]},
                    netvalue: {rules: [
                            {required: true, message: '请选择!'},
                        ]},
                    channelvalue: {rules: [
                      {required: true, message: '请选择!'},
                    ]},
                    heartbeatSwitch: {rules: [
                        {required: true, message: '请选择!'},
                      ]},
                    uploadSwitch: {rules: [
                        {required: true, message: '请选择!'},
                      ]},
                    ipvalue: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    portvalue: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    lightNumber: {rules: [
                        {required: true, message: '请输入!'},
                      ]},
                    lightTwoTypeCode: {rules: [
                        {required: true, message: '请输入!'},
                      ]},
                    lightOneTypeCode: {rules: [
                        {required: true, message: '请输入!'},
                      ]},
                    heartbeat: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    dataCycle: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    testCycle: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    pollingCycle: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    lightCode: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    testCount: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    testTime: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    onOff: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                    illuminance: {rules: [
                            {required: true, message: '请输入!'},
                        ]},
                },
                url: {
                    add: "/glr/glrGateway/add",
                    edit: "/glr/glrGateway/edit",
                    readDate: "/glr/glrGateway/readDate",
                    setDate: "/glr/glrGateway/setDate",
                    readLightGateWay: "/glr/glrGateway/readLightGateWay",
                    setLightGateWay: "/glr/glrGateway/setLightGateWay",
                    getOpenStatus: "/glr/glrGateway/getOpenStatus",
                    setOpenStatus: "/glr/glrGateway/setOpenStatus",
                    getIP: "/glr/glrGateway/getIP",
                    setIP: "/glr/glrGateway/setIP",
                    getGateWayMsg: "/glr/glrGateway/getGateWayMsg",
                    setGateWayMsg: "/glr/glrGateway/setGateWayMsg",
                    getPacketLoss:"/glr/glrGateway/getPacketLoss",
                    setPacketLoss:"/glr/glrGateway/setPacketLoss",
                    getGPS:"/glr/glrGateway/getGPS",
                    getTimeFrameAndDimming:"/glr/glrGateway/getTimeFrameAndDimming",
                    setTimeFrameAndDimming:"/glr/glrGateway/setTimeFrameAndDimming",
                    getIlluminance:"/glr/glrGateway/getIlluminance",
                    setIlluminance:"/glr/glrGateway/setIlluminance",
                    getManufacturerSet:"/glr/glrGateway/getManufacturerSet",
                    setManufacturerSet:"/glr/glrGateway/setManufacturerSet",
                    getRatedPower:"/glr/glrGateway/getRatedPower",
                    setRatedPower:"/glr/glrGateway/setRatedPower",
                    setSystemRestart:"/glr/glrGateway/setSystemRestart",
                    getVersionNo:"/glr/glrGateway/getVersionNo",
                    getLightType: "/glr/glrLightType/getLightType",
                }
            }
        },
        created () {
            const that = this;
            httpAction(this.url.getLightType,null,"post").then((res)=>{
              if(res.success){
                that.lightTypeList=res.result;
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
        },
        methods: {
            add () {
                this.edit({});
            },
            edit (record) {
                this.form.resetFields();
                this.model = Object.assign({}, record);
                this.title="编号:("+record.gateWayCode+")";
                this.visible = true;
                this.$nextTick(() => {
                    this.form.setFieldsValue(pick(this.model,'gateWayCode'));
                })
            },
            close () {
                this.$emit('close');
                this.visible = false;
            },
            handleCancel () {
                this.close()
            },
            readDate(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.readDate, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'dateTime':moment(res.result.dateTime,'YYYY-MM-DD HH:mm:ss')});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setDate(){
                var that=this;
                that.confirmLoading = true;
                var dateTime=this.form.getFieldValue("dateTime");
                dateTime=moment(dateTime).format("YYYY-MM-DD HH:mm:ss");
                httpAction(that.url.setDate, {gateWayCode: this.model.gateWayCode,dateTime:dateTime}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            readLightGateWay(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.readLightGateWay, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'lightGateWay':res.result.data});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setLightGateWay(){
                var that=this;
                that.confirmLoading = true;
                this.form.validateFields(['lightGateWay'],(err, values) => {
                    if (!err) {
                        var lightGateWay = this.form.getFieldValue("lightGateWay");
                        httpAction(that.url.setLightGateWay, {
                            gateWayCode: this.model.gateWayCode,
                            lightGateWay: lightGateWay
                        }, "post").then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                        });
                    }
                });
            },
            getOpenStatus(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.getOpenStatus, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'openstatusvalue':res.result.data});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setOpenStatus(){

                this.form.validateFields(['openstatusvalue'],(err, values) => {
                    if (!err) {
                        var that = this;
                        that.confirmLoading = true;
                        var openstatusvalue = this.form.getFieldValue("openstatusvalue");
                        httpAction(that.url.setOpenStatus, {
                            gateWayCode: this.model.gateWayCode,
                            openstatusvalue: openstatusvalue
                        }, "post").then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                        });
                    }});
            },
            getIP(){
                var that=this;
                that.confirmLoading = true;
                var netvalue=this.form.getFieldValue("netvalue");
                var channelvalue=this.form.getFieldValue("channelvalue");
                httpAction(that.url.getIP, {gateWayCode: this.model.gateWayCode,netvalue:netvalue,channelvalue:channelvalue}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        var data=res.result.data;
                        that.form.setFieldsValue({'netvalue':data.netvalue});
                        that.form.setFieldsValue({'channelvalue':data.channelvalue});
                        that.form.setFieldsValue({'ipvalue':data.ipvalue});
                        that.form.setFieldsValue({'portvalue':data.portvalue});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setIP(){
                this.form.validateFields(['netvalue','channelvalue','ipvalue','portvalue'],(err, values) => {
                    if (!err) {
                        var that = this;
                        that.confirmLoading = true;
                        var netvalue = this.form.getFieldValue("netvalue");
                        var channelvalue = this.form.getFieldValue("channelvalue");
                        var ipvalue = this.form.getFieldValue("ipvalue");
                        var portvalue = this.form.getFieldValue("portvalue");
                        httpAction(that.url.setIP, {
                            gateWayCode: this.model.gateWayCode,
                            netvalue: netvalue,
                            channelvalue: channelvalue,
                            ipvalue: ipvalue,
                            portvalue: portvalue
                        }, "post").then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                        });
                    }});
            },
            setIlluminance(){
                this.form.validateFields(['onOff','illuminance'],(err, values) => {
                    if (!err) {
                        var that = this;
                        that.confirmLoading = true;
                        var onOff = this.form.getFieldValue("onOff");
                        var illuminance = this.form.getFieldValue("illuminance");
                        httpAction(that.url.setIlluminance, {
                            gateWayCode: this.model.gateWayCode,
                            onOff: onOff,
                            illuminance: illuminance
                        }, "post").then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                        });
                    }});
            },
            getIlluminance(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.getIlluminance, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        that.form.setFieldsValue({'illuminanceValue':res.result.data});
                        that.$message.success(res.message);
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setManufacturerSet(){
              this.form.validateFields(['heartbeatSwitch','uploadSwitch'],(err, values) => {
                if (!err) {
                  var that = this;
                  that.confirmLoading = true;
                  var heartbeatSwitch = this.form.getFieldValue("heartbeatSwitch");
                  var uploadSwitch = this.form.getFieldValue("uploadSwitch");
                  httpAction(that.url.setManufacturerSet, {
                    gateWayCode: this.model.gateWayCode,
                    heartbeatSwitch: heartbeatSwitch,
                    uploadSwitch: uploadSwitch
                  }, "post").then((res) => {
                    if (res.success) {
                      that.$message.success(res.message);
                    } else {
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.confirmLoading = false;
                  });
                }});
            },
            getManufacturerSet(){
              var that=this;
              that.confirmLoading = true;
              httpAction(that.url.getManufacturerSet, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                if (res.success) {
                  var data=res.result.data;
                  that.form.setFieldsValue({'heartbeatSwitch':data.heartbeatSwitch});
                  that.form.setFieldsValue({'uploadSwitch':data.uploadSwitch});
                  that.$message.success(res.message);
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              });
            },
            setRatedPower(){
              this.form.validateFields(['lightOneTypeCode','lightTwoTypeCode','lightNumber'],(err, values) => {
                if (!err) {
                  var that = this;
                  that.confirmLoading = true;
                  var lightOneTypeCode = this.form.getFieldValue("lightOneTypeCode");
                  var lightTwoTypeCode = this.form.getFieldValue("lightTwoTypeCode");
                  var lightNumber = this.form.getFieldValue("lightNumber");
                  httpAction(that.url.setRatedPower, {
                    gateWayCode: this.model.gateWayCode,
                    lightOneTypeCode: lightOneTypeCode,
                    lightTwoTypeCode: lightTwoTypeCode,
                    lightNumber: lightNumber,
                  }, "post").then((res) => {
                    if (res.success) {
                      that.$message.success(res.message);
                    } else {
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.confirmLoading = false;
                  });
                }});
            },
            getRatedPower(){
              var that=this;
              that.confirmLoading = true;
              httpAction(that.url.getRatedPower, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                if (res.success) {
                  var data=res.result.data;
                  that.form.setFieldsValue({'lightOneTypeCode':data.lightOneTypeCode});
                  that.form.setFieldsValue({'lightTwoTypeCode':data.lightTwoTypeCode});
                  that.form.setFieldsValue({'lightNumber':data.lightNumber});
                  that.$message.success(res.message);
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              });
            },
            getVersionNo(){
              var that=this;
              that.confirmLoading = true;
              httpAction(that.url.getVersionNo, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                if (res.success) {
                  var data=res.result.data;
                  that.form.setFieldsValue({'hardwareVersion':data.hardwareVersion});
                  that.form.setFieldsValue({'softwareVersion':data.softwareVersion});
                  that.$message.success(res.message);
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              });
            },
            setSystemRestart(){
              this.form.validateFields([],(err, values) => {
                if (!err) {
                  var that = this;
                  that.confirmLoading = true;
                  httpAction(that.url.setSystemRestart, {
                    gateWayCode: this.model.gateWayCode,
                  }, "post").then((res) => {
                    if (res.success) {
                      that.$message.success(res.message);
                    } else {
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.confirmLoading = false;
                  });
                }});
            },
            getGateWayMsg(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.getGateWayMsg, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        var data=res.result.data;
                        that.form.setFieldsValue({'heartbeat':data.heartBeat});
                        that.form.setFieldsValue({'dataCycle':data.dataCycle});
                        that.form.setFieldsValue({'testCycle':data.testCycle});
                        that.form.setFieldsValue({'pollingCycle':data.pollingCycle});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setGateWayMsg(){
                this.form.validateFields(['heartbeat','dataCycle'],(err, values) => {
                    if (!err) {
                        var that = this;
                        that.confirmLoading = true;
                        var heartbeat = this.form.getFieldValue("heartbeat");
                        var dataCycle = this.form.getFieldValue("dataCycle");
                        var testCycle = this.form.getFieldValue("testCycle");
                        var pollingCycle = this.form.getFieldValue("pollingCycle");
                        httpAction(that.url.setGateWayMsg, {
                            gateWayCode: this.model.gateWayCode,
                            heartBeat: heartbeat,
                            dataCycle: dataCycle,
                            testCycle: testCycle,
                            pollingCycle: pollingCycle
                        }, "post").then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                        });
                    }});
            },
            getPacketLoss(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.getPacketLoss, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'testResult':res.result.data.testResult});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setPacketLoss(){
                this.form.validateFields(['lightCode','testCount','testTime'],(err, values) => {
                    if (!err) {
                        var that = this;
                        that.confirmLoading = true;
                        var lightCode = this.form.getFieldValue("lightCode");
                        var testCount = this.form.getFieldValue("testCount");
                        var testTime = this.form.getFieldValue("testTime");
                        httpAction(that.url.setPacketLoss, {
                            gateWayCode: this.model.gateWayCode,
                            lightCode: lightCode,
                            testCount: testCount,
                            testTime: testTime
                        }, "post").then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                                that.form.setFieldsValue({'lightGateWay': res.result.value});
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                        });
                    }});
            },
            getGPS(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.getGPS, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        console.info(res.result.data);
                        var data=res.result.data;
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'altitude':data.altitude});
                        that.form.setFieldsValue({'longitude':data.longitude});
                        that.form.setFieldsValue({'latitude':data.latitude});
                        that.form.setFieldsValue({'gpsCam':data.gpsCam});
                        that.form.setFieldsValue({'timeLongitude':data.timeLongitude});
                        that.form.setFieldsValue({'timeLatitude':data.timeLatitude});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            getTimeFrameAndDimming(){
                var that=this;
                that.confirmLoading = true;
                httpAction(that.url.getTimeFrameAndDimming, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
                    if (res.success) {
                        var data=res.result;
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'commandTimea':moment(data.commandTimea,'HH:mm')});
                        that.form.setFieldsValue({'typeb':data.typeb});
                        that.form.setFieldsValue({'brightValuea':data.brightValuea});
                        that.form.setFieldsValue({'brightValueb':data.brightValueb});
                        that.form.setFieldsValue({'brightValuec':data.brightValuec});
                        that.form.setFieldsValue({'typec':data.typec});
                        that.form.setFieldsValue({'brightValued':data.brightValued});
                        that.form.setFieldsValue({'brightValuee':data.brightValuee});
                        that.form.setFieldsValue({'commandTimeb':data.commandTimeb});
                        that.form.setFieldsValue({'commandTimec':data.commandTimec});
                        that.form.setFieldsValue({'commandTimed':moment(data.commandTimed,'HH:mm')});
                        that.form.setFieldsValue({'commandTimee':moment(data.commandTimee,'HH:mm')});
                        that.form.setFieldsValue({'v1Time':data.v1Time});
                        that.form.setFieldsValue({'v2Time':data.v2Time});
                        that.form.setFieldsValue({'v3Time':data.v3Time});
                        that.form.setFieldsValue({'v4Time':data.v4Time});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            },
            setTimeFrameAndDimming(){
                var that=this;
                that.confirmLoading = true;
                var commandTimea=this.form.getFieldValue("commandTimea");
                commandTimea=moment(commandTimea).format("HH:mm");
                var brightValuea=this.form.getFieldValue("brightValuea");
                var commandTimeb=this.form.getFieldValue("commandTimeb");
                var brightValueb=this.form.getFieldValue("brightValueb");

                var typeb=this.form.getFieldValue("typeb");
                var typec=this.form.getFieldValue("typec");
                var commandTimec=this.form.getFieldValue("commandTimec");
                var brightValuec=this.form.getFieldValue("brightValuec");

                var commandTimed=this.form.getFieldValue("commandTimed");
                var brightValued=this.form.getFieldValue("brightValued");

                commandTimed=moment(commandTimed).format("HH:mm");

                var commandTimee=this.form.getFieldValue("commandTimee");
                var brightValuee=this.form.getFieldValue("brightValuee");
                commandTimee=moment(commandTimee).format("HH:mm");

                httpAction(that.url.setTimeFrameAndDimming, {brightValuee:brightValuee,commandTimee:commandTimee,brightValued:brightValued,commandTimed:commandTimed,brightValuec:brightValuec,commandTimec:commandTimec,typec:typec,typeb:typeb,gateWayCode: this.model.gateWayCode,commandTimea:commandTimea,brightValuea:brightValuea,commandTimeb:commandTimeb,brightValueb:brightValueb}, "post").then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.form.setFieldsValue({'lightGateWay':res.result.value});
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                });
            }
        }
    }
</script>